package com.emex.app.stuff.utils;

import com.emex.app.shared.data.Client;
import com.emex.app.shared.data.JuridicalPerson;
import com.emex.app.shared.data.User;

/**
 *
 * @author Sergey Karavaev
 */
public class StringUtilities {

    public static String getManagerFIO(User user) {
        String fio = "";
        if (null != user) {
            fio = user.getSurname() + " "
                    + user.getName().charAt(0) + ". "
                    + user.getPatronymic().charAt(0) + ".";
        }

        return fio;
    }

    public static String getClientFIO(Client client) {
        String fio = "";
        if (null != client) {
            fio = client.getSurname() + " "
                    + client.getName().charAt(0) + ". "
                    + client.getPatronymic().charAt(0) + ".";
        }

        return fio;
    }

    public static String fromUpperCase(String toChange) {
        if (toChange.length() > 0) {
            toChange = Character.toUpperCase(toChange.charAt(0)) + toChange.substring(1);
        }
        return toChange;
    }

    public static String formatStringFromSpecialCharacters(String toFormat) {
        if (null != toFormat && !toFormat.isEmpty()) {
            toFormat = toFormat.replaceAll("\t", " ");
            String result = toFormat.replaceAll("\\s+", " ");
            return result;
        }
        return null;
    }

    public static String formatPositionCode(String codeToFormat) {
        return codeToFormat.replaceAll("-", "").replaceAll(" ", "");
    }

    public static String getSellerJurPersonDescription(JuridicalPerson jp) {
        StringBuilder builder = new StringBuilder();
        builder.append("Продавец: ").append(jp.getName()).append("\n");
        builder.append("Адрес: ").append(jp.getAddress().replaceAll("\n", " ")).append("\n");
        builder.append("ИНН/КПП продавца: ").append(jp.getInn()).append("/").append(jp.getKpp()).append("\n");
        builder.append("Грузополучатель и его адрес:").append(jp.getConsignee()).append("\n");
        builder.append("К платежно-расчетному документу").append("\n");
        return builder.toString();
    }

    public static String getBuyerJurPersonDescription(JuridicalPerson jp) {
        StringBuilder builder = new StringBuilder();
        builder.append("Покупатель: ").append(jp.getName()).append("\n");
        builder.append("Адрес: ").append(jp.getAddress().replaceAll("\n", " ")).append("\n");
        builder.append("ИНН/КПП покупателя: ").append(jp.getInn()).append("/").append(jp.getKpp()).append("\n");
        return builder.toString();
    }

    public static String getIPPassport(JuridicalPerson jp) {
        StringBuilder builder = new StringBuilder();
        builder.append("Свидетельство: серия ").append(jp.getSvSeries()).
                append(" № ").append(jp.getSvNumber()).append(" от ").
                append(DateUtils.getFormatedDateString(jp.getSvDate())).
                append(" выдано ").append(jp.getSvIssuedBy());
        return builder.toString();
    }

    public static String getAddressantForSchet(JuridicalPerson jp) {
        StringBuilder builder = new StringBuilder();
        builder.append("Продавец: ").append(jp.getName()).append("\n");
        builder.append("Адрес: ").append(jp.getAddress().replaceAll("\n", " ")).append("\n");
        builder.append("ИНН: ").append(jp.getInn()).append("\n");
        builder.append("Расчетный счет: ").append(jp.getBankAccount()).append("\n");
        builder.append("Кор. счет: ").append(jp.getCorAccount()).append("\n");
        builder.append("БИК: ").append(jp.getBik()).append("\n");
        builder.append("Банк: ").append(jp.getBank()).append("\n");
        return builder.toString();
    }

}
